package com.gxa.controller;

import com.gxa.pojo.Tenantperson;
import com.gxa.service.TenantpersonService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Tenantperson)表控制层
 *
 * @author makejava
 * @since 2022-09-01 12:39:32
 */
@Api
@RestController
@RequestMapping("tenantperson")
public class TenantpersonController {
    /**
     * 服务对象
     */
    @Resource
    private TenantpersonService tenantpersonService;

    /**
     * 分页查询
     *
     * @param tenantperson 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "条件查找数据并分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantPersonId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonPeopleId", value = "人员id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonType", value = "人员类型", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonCompanyName", value = "公司名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonEducation", value = "学历", dataType = "java.lang.String", paramType = "body"),
    })
    @PostMapping("/queryByPage")
    public ResponseData queryByPage(Tenantperson tenantperson, @ApiParam(value = "页码") int page, @ApiParam(value = "每页多少条") int size) {
        ResponseData responseData = new ResponseData();
        responseData.setData(this.tenantpersonService.queryByPage(tenantperson, page, size));
        return responseData;
    }

//    /**
//     * 通过主键查询单条数据
//     *
//     * @param tenantperson 主键
//     * @return 单条数据
//     */
//    @PostMapping("/query")
//    public ResponseData query(Tenantperson tenantperson) {
//        ResponseData responseData = new ResponseData();
//        responseData.setData(this.tenantpersonService.query(tenantperson));
//        return responseData;
//    }

    /**
     * 新增数据
     *
     * @param tenantperson 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantPersonId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonPeopleId", value = "人员id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonType", value = "人员类型", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonCompanyName", value = "公司名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonEducation", value = "学历", dataType = "java.lang.String", paramType = "body"),
    })
    @PostMapping("/add")
    public ResponseData add(@RequestBody Tenantperson tenantperson) {
        ResponseData responseData = new ResponseData();
        if (this.tenantpersonService.insert(tenantperson) > 0) {
            responseData.setCode(200);
            responseData.setMsg("success");
        } else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

    /**
     * 编辑数据
     *
     * @param tenantperson 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "修改数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantPersonId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonPeopleId", value = "人员id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonType", value = "人员类型", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonCompanyName", value = "公司名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonEducation", value = "学历", dataType = "java.lang.String", paramType = "body"),
    })
    @PutMapping("/change")
    public ResponseData edit(Tenantperson tenantperson) {
        ResponseData responseData = new ResponseData();
        Tenantperson update = this.tenantpersonService.update(tenantperson);
        if (update.equals(null)) {
            responseData.setCode(404);
            responseData.setMsg("fail");
        } else {
            responseData.setCode(200);
            responseData.setData(update);
        }
        return responseData;
    }

    /**
     * 删除数据
     *
     * @param tenantperson 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "根据条件删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantPersonId", value = "id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonPeopleId", value = "人员id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonType", value = "人员类型", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonCompanyName", value = "公司名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantPersonEducation", value = "学历", dataType = "java.lang.String", paramType = "body"),
    })
    @DeleteMapping("/delete")
    public ResponseData
    deleteById(Tenantperson tenantperson) {
        ResponseData responseData = new ResponseData();
        if (this.tenantpersonService.deleteById(tenantperson)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

}

